package com.controller;

import com.entity.PriceMappingEntity;
import com.entity.vo.PriceMappingVo;
import com.service.PriceMappingService;
import com.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author mgl
 * @version 1.0
 * @description 奖项对应控制器
 * @date 2024/4/22 15:27
 */
@RestController
@RequestMapping("/priceMapping")
public class PriceMappingController {
    @Autowired
    private PriceMappingService priceMappingService;


    @GetMapping("/list")
    public R list(@RequestParam(value = "page", required = false) Integer pageNo,
                  @RequestParam(value = "limit", required = false) Integer pageSize,
                  @RequestParam(value = "contestName", required = false) String contestName) {
        Map<String,Object> map = new HashMap<>();
        int length = priceMappingService.selectAll(map).size();
        map.put("contestName", contestName);
        if (pageSize != null && pageNo != null) {
            map.put("begin", (pageNo - 1) * pageSize);
            map.put("pageSize", pageSize);
        }
        List<PriceMappingVo> list = priceMappingService.selectAll(map);
        System.out.println(list);
        return R.ok().put("data", list).put("length",length);
    }

    @PostMapping("/add")
    public R add(@RequestBody PriceMappingEntity entity) {
        priceMappingService.insert(entity);
        return R.ok();
    }

    @PostMapping("/update")
    public R update(@RequestBody PriceMappingEntity entity) {
        priceMappingService.updateById(entity);
        return R.ok();
    }

    @GetMapping("/delete")
    public R delete(@RequestParam("ids") List<Integer> ids) {
        priceMappingService.deleteBatchIds(ids);
        return R.ok();
    }

}
